package Top_Interview_Questions.Tree;

import Top_Interview_Questions.Tree.Supple.TreeNode;

/**
 * @Author: 吕庆龙
 * @Date: 2020/2/8 17:26
 * <p>
 * 功能描述:
 */
public class _0104 {

    public static void main(String[] args) {
        _0104 test = new _0104();

        TreeNode root = new TreeNode(3);
        TreeNode node1 = new TreeNode(9);
        TreeNode node2 = new TreeNode(20);
        TreeNode node3 = new TreeNode(15);
        TreeNode node4 = new TreeNode(7);
        TreeNode node5 = new TreeNode(6);

        root.left = node1;
        root.right = node2;
        node2.left = node3;
        node2.right = node4;
        node1.left = node5;

        test.maxDepth2(root);

    }

    public int maxDepth2(TreeNode root) {
        if (root == null)
            return 0;

        int left_height = maxDepth2(root.left);
        int right_height = maxDepth2(root.right);
        return Math.max(left_height, right_height) + 1;

    }

    public int maxDepth1(TreeNode root) {

        if(root == null){
            return 0;
        }

        int leftHight = (root.left == null ? 0 : maxDepth1(root.left)) + 1;
        int rightHight = (root.right == null ? 0 : maxDepth1(root.right)) + 1;
        int count = Math.max(leftHight,rightHight);
        return count;

    }


}
